package com.minivision.sdktestdemo.controler.ui.list;

import android.content.Context;
import android.net.Uri;

import com.minivision.sdktestdemo.bean.MusicBean;
import com.minivision.sdktestdemo.model.MusicProvider;

import java.util.List;

/**
 * Created by devtang on 2016/4/8.
 */
public class MusicListControler extends ListControler<MusicBean> {
    private List<MusicBean> mBeans;

    public String getPath(int position) {
        return mBeans.get(position).getmPath();
    }

    public MusicListControler(Context context, List<MusicBean> list) {
        mProvider = MusicProvider.getInstance(context);
        if (list == null) {
            throw new IllegalArgumentException("list不能为空");
        }
        mBeans = list;
    }

    public void adjustOrder() {
        mProvider.sort(mBeans);
    }

    public List<MusicBean> getBeans() {
        return mBeans;
    }

    public boolean notifyDataChanged() {
        boolean flag = mProvider.isChanged();
        mProvider.setChanged(false);
        return flag;
    }

    @Override
    public boolean isItemPlayed(String key, int position) {
        return key.equals(getPath(position));
    }

    @Override
    public String getTitle(int position) {
        return mBeans.get(position).getmMusicName();
    }

    @Override
    public String getContent(int position) {
        return mBeans.get(position).getmSingerName() + " - "
                + mBeans.get(position).getmAlbumName();
    }

    @Override
    public int getType() {
        return ListControler.MUSICS;
    }

    @Override
    public Uri getPicUrl(int position) {
        return null;
    }

    @Override
    public int size() {
        return mBeans.size();
    }

}
